package Login.servlet;

import Login.Service.BookService;
import Login.entity.Book;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "edit", urlPatterns = "/edit")
public class editServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            String bookId = req.getParameter("id");
            BookService bookService = new BookService();
            if (!bookService.hasSession(req.getSession(), resp)) {
                return;
            }
            Book book = bookService.getBook(bookId);
            req.setAttribute("book", book);
            req.getRequestDispatcher("edit.jsp").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }
}
